#pragma once
/***************************************************************************************************
 *Copyright(C),2015-2020,Sumscope
 *FileName	    :  BondDealTermRange
 *Author	    :  Givins.zhu
 *Version	    :  1.0
 *Date		    :  2016/07/11
 *Desc		    :  成交统计中保存期限的取值范围。
 *Function     :
 *History	    :
 *Email        :  Givins.zhu@sumscope.com
 *Requirement  :
 ***************************************************************************************************/
#include <qbprotocol/include/SSQBModel.h>

#include <algorithm>
#include <list>
#include <map>
#include <string>

#include "../bondlib.h"

using namespace std;

class S_BONDLIB_EXPORT CBondDealTermRange {
 public:
  enum emBondType {
    bondType_Interest = 0,  // 利率债
    bondType_Credit,        // 信用债
    bondType_NCDPrimary,    // NCD一级报价
    bondType_NCD            // NCD二级成交
  };
  enum emTermRange {
    termRg_Credit = 11,
    termRg_Interest = 12,
    termRg_NCDPrimary = 6,
    termRg_NCD = 8  // NCD二级成交
  };
  enum emDiffType {
    diffType_PreClose = 0,  // 按昨收涨跌
    diffType_CDC            // 按中债偏离
  };

 public:
  static CBondDealTermRange& instance();
  virtual ~CBondDealTermRange();

 public:
  void InitDefaultRange(sBondDealTermRgUnit& unit,
                        CBondDealTermRange::emBondType range);
  void UpdateRange(xQBBondDealTermRgAck* pAck, bool bInit);  // 更新期限范围
  int GetDiffType(CBondDealTermRange::emBondType nType);
  bool GetRange(sBondDealTermRgUnit& termRg,
                CBondDealTermRange::emBondType nType);  // 获取期限范围
  bool GetRangeColumn(CBondDealTermRange::emBondType nType, int nDays,
                      std::set<int>& setResult);
  bool IsInited();
  map<string, sBondDealTermRgUnit>* GetMap(
      CBondDealTermRange::emBondType nType);
  int CalcDays(const char* pStr);

 private:
  CBondDealTermRange();

 public:
  int m_diffInterest;
  int m_diffCredit;
  int m_diffNCD;
  int m_diffNCDPrimary;

  map<string, sBondDealTermRgUnit> m_mapInterestRange;    // 利率债
  map<string, sBondDealTermRgUnit> m_mapCreditRange;      // 信用债
  map<string, sBondDealTermRgUnit> m_mapNCDRange;         // NCD二级成交
  map<string, sBondDealTermRgUnit> m_mapNCDPrimaryRange;  // NCD一级报价
};
